package com.itkim.qian.interceptor;

import com.itkim.qian.utils.JWTUtil;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 配置JWT拦截器
 */
public class JWTInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler){
        String token = request.getHeader("token");
        try {
            JWTUtil.verify(token);
        } catch (Exception e) {
            throw new RuntimeException("验证失败");
        }
        return true;
    }
}